package cn.hx.fristgame;

import java.awt.*;

/**
 * 炮弹类
 */
public class shell extends gameObj {
    int x =200 ;
    int y = 200;
    double degree;
    public shell(){
        degree = Math.random()*Math.PI*2;
    }
    public void draw(Graphics g){
        Color a = g.getColor();     //保存画笔颜色，以便用完之后还原

        g.setColor(Color.YELLOW);   //设置画笔颜色
        g.fillOval(x,y,constant.SHELL_WIDTH,constant.SHELL_HEIGHT);
        x += constant.SHELL_SPEED*Math.cos(degree);
        y += constant.SHELL_SPEED*Math.sin(degree);

        if (x < 0 || x > constant.GAME_WIDTH - constant.SHELL_WIDTH){
            degree = Math.PI - degree;
        }
        if (y < 30 || y > constant.GAME_HEIGHT - constant.SHELL_HEIGHT){
            degree = - degree;
        }

        g.setColor(a);      //还原画笔颜色

    }

}
